<template>
  <div class="app-container">
    <!-- 基本信息 -->
    <div class="titleLineGreen">基本信息</div>
    <div class="info flex">
      <el-image
        v-if="info.avatar.includes('http')"
        class="info_avatar"
        :src="info.avatar"
        :preview-src-list="[info.avatar]"
      ></el-image>
      <div v-if="!info.avatar.includes('http')" class="avatar_name">
        {{ getLastTwoCharacters(info.teacherName) }}
      </div>
      <div class="info_right">
        <!-- 教师信息 -->
        <div class="info_teacherinfos">
          <div class="flex info_teacherinfo_line1">
            <div class="info_teacherinfo_line_item flex">
              <el-tooltip class="item" effect="dark" :content="info.teacherName" placement="top-start">
                <div class="info_teacherinfo_line_item_nickname overTxt">
                  {{ info.teacherName }}
                </div>
              </el-tooltip>

              <img v-if="info.sex == 1" class="sex" src="@/assets/images/sex_women.png" alt="加载失败"/>
              <img v-else class="sex" src="@/assets/images/sex_man.png" alt="加载失败"/>
            </div>
            <el-tooltip class="item" effect="dark" :content="info.branchName" placement="top-start">
              <div class="info_teacherinfo_line_item overTxt">
                学院: {{ info.branchName }}
              </div>
            </el-tooltip>

            <div class="info_teacherinfo_line_item overTxt">
              工号: {{ info.teacherNum }}
            </div>
          </div>
          <div class="flex info_teacherinfo_line2">
            <div class="info_teacherinfo_line1_rate info_teacherinfo_line_item flex">
              <span>评分:</span>
              <el-rate disabled show-score text-color="#ff9900" score-template="{value}分"
                       :value="info.teacherStar ? info.teacherStar.toFixed(1) - 0 : 0"
              ></el-rate>
            </div>
            <div class="info_teacherinfo_line_item overTxt">
              身份证: {{ (info.idCard ? info.idCard : '--') | regIdCard }}
            </div>
            <div class="info_teacherinfo_line_item overTxt">
              手机号:
              {{ (info.phoneNumber ? info.phoneNumber : '--') | regPhone }}
            </div>
          </div>
        </div>
        <!-- 数据卡片 -->
        <div class="info_dataCards flex">
          <div class="info_dataCard" style="width: 320px; margin: 0 0 0 0">
            <!-- 数据卡片的顶行 -->
            <div class="info_dataCard_topLine flex">
              <div class="info_dataCard_topLine_point" style="background: rgba(67, 218, 43, 1)"></div>
              <div class="info_dataCard_topLine_lable">当前负责</div>
            </div>
            <!-- 数据卡片数据行 -->
            <div class="info_dataCard_dateLine info_dataCard_dateLine1 flex">
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">主讲课程</div>
                <div class="info_dataCard_dateLine_item_value">
                  {{
                    responsibleData.usingCourseNum
                      ? responsibleData.usingCourseNum
                      : 0
                  }}
                </div>
              </div>
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">辅助课程</div>
                <div class="info_dataCard_dateLine_item_value">
                  {{ responsibleData.helpNum ? responsibleData.helpNum : 0 }}
                </div>
              </div>
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">负责工作站</div>
                <div class="info_dataCard_dateLine_item_value">
                  {{
                    responsibleData.workstationNum
                      ? responsibleData.workstationNum
                      : 0
                  }}
                </div>
              </div>
            </div>
          </div>
          <div class="info_dataCard" style="width: 420px; margin: 0 0 0 24px">
            <!-- 数据卡片的顶行 -->
            <div class="info_dataCard_topLine flex">
              <div class="info_dataCard_topLine_point" style="background: rgba(44, 172, 255, 1)"></div>
              <div class="info_dataCard_topLine_lable">
                工作数据 <span>(本学期/历史)</span>
              </div>
            </div>
            <!-- 数据卡片数据行 -->
            <div class="info_dataCard_dateLine info_dataCard_dateLine2 flex">
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">优秀率</div>
                <div class="info_dataCard_dateLine_item_value">
                  {{
                    workData && workData.goodPer
                      ? workData.goodPer + '%'
                      : '--'
                  }}<span></span>
                </div>
              </div>
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">平均成绩</div>
                <div class="info_dataCard_dateLine_item_value">
                  {{
                    workData && workData.avgScore
                      ? workData.avgScore.toFixed(2)
                      : '--'
                  }}<span v-if="workData && workData.hisAvgScore">/{{
                    workData && workData.hisAvgScore
                      ? workData.hisAvgScore.toFixed(2)
                      : '--'
                  }}</span>
                </div>
              </div>
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">批卷数</div>
                <div class="info_dataCard_dateLine_item_value">
                  {{
                    workData && workData.examMarkNum
                      ? workData.examMarkNum
                      : '--'
                  }}<span v-if="workData && workData.totalExamMarkNum">/{{
                    workData && workData.totalExamMarkNum
                      ? workData.totalExamMarkNum
                      : '--'
                  }}</span>
                </div>
              </div>
              <div class="info_dataCard_dateLine_item">
                <div class="info_dataCard_dateLine_item_lable">答疑数量</div>
                <div class="info_dataCard_dateLine_item_value">
                  {{
                    workData && workData.totalExamMarkNum
                      ? workData.totalExamMarkNum
                      : '--'
                  }}<span></span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 评价 -->
    <div class="titleLineGreen" style="margin-top: 40px">评价</div>

    <el-form style="margin-top: 20px" :model="queryParams" ref="queryForm" size="small" :inline="true"
             label-width="80px"
    >
      <el-form-item label="学生" prop="name">
        <el-input style="width: 150px" v-model="queryParams.name" placeholder="请输入学生名称" clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级" prop="classId">
        <el-select style="width: 150px" filterable v-model="queryParams.classId" placeholder="请选择" clearable>
          <el-option v-for="item in classes" :key="item.classId" :label="item.className" :value="item.classId"/>
        </el-select>
      </el-form-item>
      <el-form-item label="评价" prop="minNum" v-if="showSearch">
        <el-input-number @input="handleInputNumberChange1" :precision="0" style="width: 100px !important" :min="0"
                         :max="5" controls-position="right" v-model="queryParams.minNum" placeholder="最低评价" clearable
                         @keyup.enter.native="handleQuery"
        />
        至
        <el-input-number :precision="0" @input="handleInputNumberChange2" style="width: 100px !important" :min="0"
                         :max="5" controls-position="right" v-model="queryParams.maxNum" placeholder="最高评价" clearable
                         @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评价时间" prop="classId" v-if="showSearch">
        <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="queryParams.date" type="daterange" align="right"
                        unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
                        :picker-options="$pickerOptions"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="学期" prop="semesterId">
        <el-select style="width: 150px" filterable v-model="queryParams.semesterId" placeholder="请选择学期" clearable>
          <el-option label="全部" :value="''"></el-option>
          <el-option v-for="item in schoolSemesterList" :key="item.semesterId" :label="item.semesterName"
                     :value="item.semesterId"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button v-preventReClick type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button v-preventReClick icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
      <right-toolbar style="margin-top: 3px" :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-form>

    <el-table v-loading="loading" :data="postList">
      <el-table-column label="学生" align="center" prop="name">
        <template slot-scope="scope">
          <div>{{ scope.row.studentName }}({{ scope.row.studentNum }})</div>
        </template>
      </el-table-column>
      <el-table-column label="班级(学院-专业)" align="center" prop="class_name">
        <template slot-scope="scope">
          <div>
            {{ scope.row.className }}({{ scope.row.branchName }}-{{
              scope.row.majorName
            }})
          </div>
        </template>
      </el-table-column>
      <el-table-column sortable label="分数" align="center" prop="score">
        <template #header>
          分数
          <el-tooltip class="item" effect="dark" placement="bottom">
            <i class="el-icon-question shou" style="font-size: 16px; vertical-align: middle; margin-left: 5px"></i>
            <div slot="content">
              <div>"0"：该课程的考核成绩</div>
              <div>" "：该课程没有考核</div>
              <div>"-"：学生尚未完成该课程</div>
            </div>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column align="center" v-if="gradeType == 1" sortable>
        <template #header> 百分制</template>
        <template slot-scope="scope">
          <div>{{ scope.row.score }}</div>
        </template>
      </el-table-column>
      <el-table-column align="center" sortable v-if="gradeType == 2">
        <template #header> 优良等级</template>
        <template slot-scope="scope">
          <div>{{ excellentLevel[scope.row.excellentLevel] }}</div>
        </template>
      </el-table-column>
      <el-table-column align="center" sortable v-if="gradeType == 3">
        <template #header> 学分制</template>
        <template slot-scope="scope">
          <div>{{ scope.row.credit }}</div>
        </template>
      </el-table-column>
      <el-table-column label="能力水平" align="center" prop="abilityStar" sortable width="165">
        <template slot-scope="scope">
          <div style="text-align: left !important">
            <el-rate :value="scope.row.abilityStar" disabled show-score text-color="#ff9900" score-template="{value}">
            </el-rate>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="敬业精神" align="center" prop="dedicatedStar" sortable width="165">
        <template slot-scope="scope">
          <div>
            <el-rate show-score text-color="#ff9900" score-template="{value}" disabled
                     v-model="scope.row.dedicatedStar"
            >
            </el-rate>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="教学热情" align="center" prop="enthusiasmStar" sortable width="165">
        <template slot-scope="scope">
          <div>
            <el-rate show-score text-color="#ff9900" score-template="{value}" disabled
                     v-model="scope.row.enthusiasmStar"
            >
            </el-rate>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="评价时间" align="center" prop="student_evaluate_time">
        <template slot-scope="scope">
          <div>
            {{ parseTime(scope.row.studentEvaluateTime) }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-preventReClick size="mini" type="text" icon="el-icon-view"
                     @click="handleDetail(scope.row)"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <teacherDetailDia :open.sync="open" :item="item" :teacherId="$route.query.teacherId"></teacherDetailDia>
  </div>
</template>

<script>
import { getSchoolSemesterList } from '@/api/schoolSemester/schoolSemester'
import teacherDetailDia from './components/teacherDetailDia'
import { getLastTwoCharacters } from '@/utils/util'
import {
  teacherInfoAndWorkInfo,
  getStuAppraise
} from '@/api/schoolOrganization/teacher'

export default {
  components: { teacherDetailDia },
  dicts: ['sys_course_type'],
  props: {},
  data() {
    return {
      getLastTwoCharacters: (name) => {
        return getLastTwoCharacters(name)
      },
      schoolSemesterList: [],
      gradeType: null,
      open: false,
      item: {},
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 9999,
        semesterId: '',
        workstationId: undefined,
        classId: undefined,
        date: undefined,
        minNum: 0,
        maxNum: 5
      },
      info: {
        avatar:''
      },
      responsibleData: {},
      workData: {},
      classes: []
    }
  },
  watch: {
    'queryParams.minNum': function(val) {
    }
  },
  created() {
  },
  mounted() {
    this.getSchoolSemester()
    this.getTeacherInfoAndWorkInfo()
    this.getList()
  },
  methods: {
    async getSchoolSemester() {
      let res = await getSchoolSemesterList()
      const { code, rows } = res
      if (code == 200) {
        this.schoolSemesterList = rows
      }
    },
    handleDetail(item) {
      this.open = true
      this.item = item
    },
    handleInputNumberChange1(value) {
      if (value > this.queryParams.maxNum) {
        this.$nextTick(() => {
          this.$set(this.queryParams, 'minNum', this.queryParams.maxNum)
        })
      }
    },
    handleInputNumberChange2(value) {
      if (value < this.queryParams.minNum) {
        this.$nextTick(() => {
          this.$set(this.queryParams, 'maxNum', this.queryParams.minNum)
        })
      }
    },
    getList() {
      this.loading = true
      this.queryParams.begin = this.queryParams.date
        ? this.queryParams.date[0]
        : ''
      this.queryParams.end = this.queryParams.date
        ? this.queryParams.date[1]
        : ''
      delete this.queryParams.date
      getStuAppraise(this.$route.query.teacherId, this.queryParams).then(
        (response) => {
          this.postList = response.rows
          if (response.rows.length > 0) {
            this.gradeType = response.rows[0].gradeType
          }
          this.total = response.total
          this.loading = false
        }
      )
    },
    /* 获取工作详细信息 */
    async getTeacherInfoAndWorkInfo() {
      let res = await teacherInfoAndWorkInfo(this.$route.query.teacherId)
      this.info = res.data
      this.responsibleData = res.data
      this.classes = res.data.classList
      this.workData = res.data
    },
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryParams.minNum = 0
      this.queryParams.maxNum = 5
      this.handleQuery()
    }
  }
}
</script>
<style scoped lang="scss">
.info.flex {
  margin: 23px 0 0 0;

  .info_avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    box-sizing: border-box;
    border: 1px solid rgba(229, 229, 229, 1);
    margin: 0 24px 0 10px;
  }

  .avatar_name {
    margin: 0 24px 0 10px;
    border: 1px solid #eeeeee;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: PingFangSC, PingFang SC, sans-serif;
    font-weight: 600;
    color: #ffffff;
    background: #ff7c32;
  }

  .info_right {
    .info_teacherinfos {
      .info_teacherinfo_line_item {
        box-sizing: border-box;
        padding-right: 25px;
        width: 276px;
        font-size: 14px;
        font-weight: 400;
        line-height: 20px;
        color: rgba(96, 98, 102, 1);

        .info_teacherinfo_line_item_nickname {
          font-size: 18px;
          font-weight: 600;
          line-height: 20px;
          color: rgba(51, 51, 51, 1);
          max-width: 227px;
        }

        .sex {
          margin: 5px 0 0 5px;
          width: 12px;
          height: 12px;
        }
      }

      .info_teacherinfo_line1 {
        margin-top: 3px;
      }

      .info_teacherinfo_line2 {
        margin-top: 15px;
      }
    }

    .info_dataCards {
      margin-top: 22px;

      .info_dataCard {
        height: 112px;
        border-radius: 8px;
        background: rgba(255, 255, 255, 1);
        box-shadow: 0 0 12px rgba(99, 99, 99, 0.14);
        box-sizing: border-box;
        padding: 16px 0 0 20px;

        .info_dataCard_topLine.flex {
          .info_dataCard_topLine_point {
            margin: 5px 8px 0 0;
            width: 10px;
            height: 10px;
            border-radius: 5px;
          }

          .info_dataCard_topLine_lable {
            font-size: 14px;
            font-weight: 600;
            line-height: 20px;
            color: rgba(51, 51, 51, 1);

            span {
              margin: 4px 0 0 0;
              font-size: 10px;
              font-weight: 400;
              line-height: 14px;
              color: rgba(51, 51, 51, 1);
            }
          }
        }

        .info_dataCard_dateLine2 {
          .info_dataCard_dateLine_item:last-of-type {
            width: 60px !important;
          }
        }

        .info_dataCard_dateLine1 {
          .info_dataCard_dateLine_item:last-of-type {
            width: 92px !important;
          }
        }

        .info_dataCard_dateLine.flex {
          margin-top: 20px;

          .info_dataCard_dateLine_item {
            width: 100px;

            .info_dataCard_dateLine_item_lable {
              font-size: 12px;
              font-weight: 400;
              line-height: 17px;
              color: rgba(153, 153, 153, 1);
            }

            .info_dataCard_dateLine_item_value {
              margin-top: 4px;
              font-size: 18px;
              font-weight: 600;
              line-height: 25px;
              color: rgba(238, 62, 62, 1);

              span {
                margin: 4px 0 0 0;
                font-size: 12px;
                font-weight: 400;
                line-height: 16px;
                color: rgba(51, 51, 51, 1);
              }
            }
          }
        }
      }
    }
  }
}
</style>
